package com.example.text.ui.mall.adepter


import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.bigkoo.convenientbanner.holder.Holder
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.example.text.R
import com.example.text.databinding.ItemMallHomeBannerChildBinding
import com.example.text.ui.mall.model.MallBanner



class MallBannerHolder(
    private val withBtn: Boolean = true,
    private val onBookingClick: ((MallBanner) -> Unit)? = null
) : Holder<MallBanner> {
    private var mBinding: ItemMallHomeBannerChildBinding? = null

    override fun createView(context: Context): View {
        mBinding = ItemMallHomeBannerChildBinding.inflate(LayoutInflater.from(context))
        //return mBinding!!.root
        return mBinding?.root ?: throw IllegalStateException()
    }

    override fun UpdateUI(context: Context, position: Int, item: MallBanner) {
        mBinding?.item = item
        mBinding?.withBtn = withBtn && item.type == "in" && item.productType == "vehicle"
        // 使用Glide加载图片
        mBinding?.picBanner?.let {
            Glide.with(context)
                .load(item.imageUrl)
                .centerCrop()
                .placeholder(R.mipmap.icon_mall_placeholder) // 加载中的占位图
                .error(R.mipmap.icon_mall_placeholder)       // 加载失败的占位图
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(it)
        }
        mBinding?.picBanner?.setOnClickListener {
            /**banner跳转*/
        }
    }

}



